package com.shuwen.gcdj.controller.statistics;

import com.shuwen.gcdj.bean.conditionMonitoring.request.*;
import com.shuwen.gcdj.bean.conditionMonitoring.response.*;
import com.shuwen.gcdj.common.annotation.JWTAuth;
import com.shuwen.gcdj.common.api.CommonResult;
import com.shuwen.gcdj.controller.AuthController;
import com.shuwen.gcdj.service.statistic.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/***
 ** Created YangX
 ** Date:2023/5/9
 */
@Api(tags = "故障监测")
@RestController
@RequestMapping("/faultMonitoring")
@Slf4j
public class FaultMonitoringController extends AuthController {
    @Autowired
    private StatisticsTrendstabilityService statisticsTrendstabilityService;
    @Autowired
    private StatisticsShocksensorService statisticsShocksensorService;
    @Autowired
    private StatisticsMechanismVibrationService statisticsMechanismVibrationService;
    @Autowired
    private FaultMonitoringService faultMonitoringService;

    @ApiOperation(value = "应变传感器点位")
    @PostMapping(value = "/getStrainSensorObject")
    @JWTAuth
    public CommonResult<List<SensorPointPositionResp>> getStrainSensor(@RequestBody StrainSensorPointQueryReq req) {
        return faultMonitoringService.getStrainSensor(req);
    }

    @ApiOperation(value = "倾角传感器点位")
    @PostMapping(value = "/getTiltSensorObject")
    @JWTAuth
    public CommonResult<List<SensorPointPositionResp>> getTiltSensor(@RequestBody TiltSensorPointReq req) {
        return faultMonitoringService.getTiltSensor(req);
    }

    @ApiOperation(value = "应变传感器当前历史趋势")
    @PostMapping(value = "/getStrainSensorTendencyByNow")
    @JWTAuth
    public CommonResult<StrainSensorTendencyNowResp> getStrainSensorTendencyByNow(@RequestBody StrainSensorTendencyByNowReq req) {

        return faultMonitoringService.getStrainSensorTendencyByNow(req);
    }

    @ApiOperation(value = "应变传感器对象")
    @GetMapping(value = "/getStrainSensorEnum")
    @JWTAuth
    public CommonResult<List<StrainSensorObjResp>> getStrainSensorEnum() {
        List<StrainSensorObjResp> resp = new ArrayList<>();
        StrainSensorObjResp sensorObjResp1 = new StrainSensorObjResp();
        sensorObjResp1.setName("应变");
        sensorObjResp1.setValue(1);
        resp.add(sensorObjResp1);
        StrainSensorObjResp sensorObjResp2 = new StrainSensorObjResp();
        sensorObjResp2.setName("应力");
        sensorObjResp2.setValue(2);
        resp.add(sensorObjResp2);
        return CommonResult.success(resp);
    }

    @ApiOperation(value = "获取震动传感器点位")
    @PostMapping(value = "/getSensorPointPosition")
    @JWTAuth
    public CommonResult<List<StrainSensorResp>> getSensorPointPosition(@RequestBody VibratingSensorPointReq req) {
        return faultMonitoringService.getSensorPointPosition(req);
    }


    @ApiOperation(value = "获取振动特征与数值")
    @PostMapping(value = "/getStatisticsShockSensorByLocation")
    @JWTAuth
    public CommonResult<List<StatisticsShockSensorResp>> getStatisticsShockSensorByLocation(@RequestBody ShockSensorObjectQueryReq req) {
        return statisticsShocksensorService.getStatisticsShockSensorList(req);
    }

    @ApiOperation(value = "应变传感器历史趋势")
    @PostMapping(value = "/getStrainSensorTendency")
    @JWTAuth
    public CommonResult<StrainSensorTendencyResp> getStrainSensorTendency(@RequestBody StrainSensorQueryReq req) {
        return statisticsTrendstabilityService.getStrainSensorTendency(req);
    }

    @ApiOperation(value = "传感器实时数据")
    @PostMapping(value = "/getStrainSensorByDateNow")
    @JWTAuth
    public CommonResult<List<StatusSensorDateNowResp>> getStrainSensorByDateNow(@RequestBody StrainSensorDateNowQueryReq req) {
        return CommonResult.success(faultMonitoringService.getStrainSensorByDateNow(req));
    }

    @ApiOperation(value = "获取震动源与震动原因")
    @PostMapping(value = "/getShockSensorMechanismVibration")
    @JWTAuth
    public CommonResult<List<StatisticsMechanismVibrationResp>> getShockSensorMechanismVibration(@RequestBody ShockSensorObjectQueryReq req) {
        return statisticsMechanismVibrationService.getShockSensorMechanismVibration(req);
    }

    @ApiOperation(value = "获取震动传感器频域图")
    @PostMapping(value = "/getShockSensor")
    @JWTAuth
    public CommonResult<List<StatisticsHealthResp>> getShockSensor(@RequestBody ShockSensorQueryReq req) {
        return faultMonitoringService.getShockSensor(req);
    }

    @ApiOperation(value = "首页趋势健康度")
    @GetMapping(value = "/getStatisticsHealth/{equipmentCode}")
    @JWTAuth
    public CommonResult<StatisticsHealthByIndexResp> getStatisticsHealth(@PathVariable String equipmentCode) {
        return faultMonitoringService.getStatisticsHealth(equipmentCode);
    }



    @ApiOperation(value = "获取倾角传感器历史趋势")
    @PostMapping(value = "/getTiltTrendstabilityHistory")
    @JWTAuth
    public CommonResult<List<TiltTrendstabilityHistoryResp>> getTiltTrendstabilityHistory(@RequestBody TiltTrendstabilityHistoryReq req) {
        return faultMonitoringService.getTiltTrendstabilityHistory(req);
    }
}
